########################### GPIgroup生存曲线(Figure2) ##########################
library(readr)
library(survival)
library(survminer)
library(ggplot2)
getwd()
setwd("D:/Users/GCR/Documents")
demo <- read_csv("data.csv")
demo[,c('r_IPI','r_RIPIGOOD','r_NCCNIPI','r_GPIgroup')] <- lapply(demo[,c('r_IPI','r_RIPIGOOD','r_NCCNIPI','r_GPIgroup')],factor)

dev <- demo[demo$s_group==0,]
vad <- demo[demo$s_group==1,]
fit <- survfit(Surv(z_Time,y_year2OS==1)~r_GPIgroup ,data = dev)
p <- ggsurvplot(fit,
                data = dev,
                ggtheme = theme_bw(),      #change ggplots theme
                palette = c("#E3B800", "#2E9FDF", "#2E9FAD"),
                xlab = "Time(months)", # 指定x轴标签
                ylab = "overall survival probability",
                linetype = 1,
                legend.title = "", # 设置图例标题
                risk.table = T,#add risk tabel绘制累计风险曲线
                risk.tabel.col="GPI group",  #change risk tabel color by groups
                risk.table.height = 0.25, # risk table高度
                legend.labs = c("Low", "Intermediate", "High") # 指定图例分组标签
)
p
ggsave("KMsurvival.pdf", plot=print(p),device = 'pdf' )

